<?php
//Functie maakt verbinding met database
function connect(){
  $db_host = 'localhost';
  $db_user = 'markpost_admin';
  $db_pass = 'WPkAQUr6';
  $db_name = 'markpost_main';
  
  mysql_connect($db_host, $db_user, $db_pass) or die ("Verbinding met server mislukt.");
  mysql_select_db($db_name) or die ("Verbinding met database mislukt.");
  
  unset($db_host);
  unset($db_user);
  unset($db_pass);
  unset($db_name);
}//connect

//Functie zet zet datum om in nederlandse stijl
function datumomzetten($datum){
  $datumarray 	= explode("-", $datum);
  $dag 		= $datumarray[2];
  $maand	= $datumarray[1];
  $jaar		= $datumarray[0];

  $maand_array 	= array("januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december");
  $maand 	= $maand_array[$maand - 1];
  $datum 	= "$dag $maand $jaar";
  
  return $datum;
}//datumomzetten

//Functie die de taal ophaald
function getDefaultLanguage() {
   if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
		switch(parseDefaultLanguage($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
			case "nl-nl": 
				$taal = 'nl'; 
				break;
			default: 
				$taal = 'en';
				break;
		}//switch
      return $taal;
	}else
      return 'en';
}//getDefaultLanguage

function parseDefaultLanguage($http_accept, $deflang = "en") {
   if(isset($http_accept) && strlen($http_accept) > 1)  {
      # Split possible languages into array
      $x = explode(",",$http_accept);
      foreach ($x as $val) {
         #check for q-value and create associative array. No q-value means 1 by rule
         if(preg_match("/(.*);q=([0-1]{0,1}\.\d{0,4})/i",$val,$matches))
            $lang[$matches[1]] = (float)$matches[2];
         else
            $lang[$val] = 1.0;
      }

      #return default language (highest q-value)
      $qval = 0.0;
      foreach ($lang as $key => $value) {
         if ($value > $qval) {
            $qval = (float)$value;
            $deflang = $key;
         }
      }
   }
   return strtolower($deflang);
}


//Instagram =========================================
// Supply a user id and an access token
$userid = "28312815";
$accessToken = "28312815.ab103e5.8281b1261dee4106a8ca3b79b5fe6feb";

// Gets our data
function fetchData($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 20);
	$result = curl_exec($ch);
	curl_close($ch); 
	return $result;
}//fetchData

function sendemail(){
	if(!empty($_POST['name']))
		$name = $_POST['name'];
	else
		return false;
		
	if(!empty($_POST['email']))
		$email = $_POST['email'];
	else
		return false;
		
	if(!empty($_POST['website']))
		$website = $_POST['website'];
	else
		$website = 'Empty';
		
	if(!empty($_POST['subject']))
		$subject = $_POST['subject'];
	else
		return false;
		
	if(!empty($_POST['message']))
		$message = $_POST['message'];
	else
		return false;
		
	if(!$error){
		// Reciever
		$to = 'markpost@mark-post.nl';
		
		// Message
		$message = '
			<html>
				<head>
					<title>Contactform: '.$subject.' by '.$name.'</title>
				</head>
				<body>
					<p><strong>Contactform: '.$subject.' by '.$name.'</strong></p>
					<table>
						<tr>
							<td>Name:</td><td>'.$name.'</td>
						</tr>
						<tr>
							<td>E-mail:</td><td>'.$email.'</td>
						</tr>
						<tr>
							<td>Website:</td><td>'.$website.'</td>
						</tr>
						<tr>
							<td>Subject:</td><td>'.$subject.'</td>
						</tr>
						<tr>
							<td>Message</td><td>'.$message.'</td>
						</tr>
					</table>
				</body>
			</html>';
			
		// To send HTML mail, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		
		// Additional headers
		$headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";
		
		// Mail it
		if(mail($to, $subject, $message, $headers))
			return true;
		else
			return false;
	}//if
}//sendemail
?>